package com.bawei.mall.product.controller;

import com.bawei.common.core.domain.R;
import com.bawei.mall.product.domain.Vo.CarVo;
import com.bawei.mall.product.domain.Vo.OrderVo;
import com.bawei.mall.product.service.ICCarService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：liurui
 * @Package：com.bawei.mall.search.controller
 * @Project：mall_cloud
 * @name：ShoppingCartController
 */
@RestController
@Log4j2
@RequestMapping("/car")
public class CCarController {
    @Autowired
    private ICCarService service;

    /**
     * 查询购物车列表
     * @return
     */
    @GetMapping("/list")
    public R<List<CarVo>> list(){
        List<CarVo> list=service.listt();
        return R.ok(list);
    }

    /**
     * 添加购物车
     */
    @PostMapping("add")
    public R add(@RequestParam Integer productId,@RequestParam Integer productSkuId){
        service.add(productId,productSkuId);
        return R.ok();
    }


    /**
     * 清空购物车
     */
    @PostMapping("/clear")
    public R clear(){
        service.clear();
        return R.ok();
    }

    /**
     * 修改数量
     * @param id
     * @param quantity
     * @return
     */
    @PostMapping("/quantity")
    public R quantity(@RequestParam Integer id,@RequestParam Integer quantity){
        service.quantity(id,quantity);
        return R.ok();
    }

    /**
     * 生成订单
     * TODO 无法使用，已经迁移到COrderController
     */
    @PostMapping("/generateConfirmOrder")
    public R<OrderVo> generateConfirmOrder(@RequestBody Integer[] cartIds){
        OrderVo orderVo=service.generateConfirmOrder(cartIds);
        return R.ok(orderVo);
    }

}
